home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Don's Hacks / AppBar Source / AppBar.p < prev    next >
Text File  |  1993-06-17  |  4KB  |  140 lines

  1. {
  2.     $Workfile:   AppBar.p  $
  3.     $Revision:   1.0  $
  4.  
  5.     A hack that uses System 7.1's Text Services Manager to display a floating pallette of
  6.     current running apps
  7.     
  8.     This file is just a very simple application shell.  All of the interesting stuff is in
  9.     AppBarUnit.p.
  10.  
  11.     © 1993 CE Software, Inc.  All rights reserved.
  12.  
  13.     WHEN    WHO        WHAT
  14.  
  15. •••••
  16.     
  17. •••••
  18. }
  19.  
  20. PROGRAM AppBar;
  21.  
  22. USES Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, MacPrint, AppleTalk, AppleEvents,
  23.     GestaltEqu,Folders,Aliases,AppBarUnit; {$R-} {$D+}
  24.  
  25. VAR    doneFlag:    BOOLEAN;                {set when the user quits the program}
  26.     myEvent:    EventRecord;            {returned by GetNextEvent}
  27.     
  28. {--------------------------------------------------------------------------
  29.     
  30.     Apple Event handlers
  31.         Just handle the required commands.  We don't print, so just open files, open the
  32.         app, and quit.
  33.  
  34.  --------------------------------------------------------------------------}
  35. FUNCTION GotRequiredParams( theAppleEvent: AppleEvent ): OSErr ;        { <aevt> }
  36. VAR    typeCode: DescType ;
  37.     actualSize: Size ;
  38.     err: OSErr ;
  39. BEGIN
  40.     err := AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr,
  41.                     typeWildCard, typeCode, nil, 0, actualSize) ;    { nil ok: need only function result }
  42.     IF err = errAEDescNotFound THEN GotRequiredParams := noErr
  43.         ELSE IF err = noErr THEN GotRequiredParams := errAEEventNotHandled
  44.             ELSE GotRequiredParams := err ;
  45.     END ; { GotRequiredParams }
  46.  
  47.  
  48. Function  HandleAEQuit(theAppleEvent,reply:AppleEvent; refcon:longint):OSErr;
  49. begin
  50.     HandleAEQuit:=GotRequiredParams( theAppleEvent );
  51.     doneflag:=true;
  52.     end;
  53.  
  54. Function  HandleAEOpenApp(theAppleEvent,reply:AppleEvent; refcon:longint):OSErr;
  55. begin
  56.     HandleAEOpenApp:=GotRequiredParams( theAppleEvent );
  57.     DoOpenApp(false);
  58.     end;
  59.  
  60. PROCEDURE InstallAppleEvents ;
  61. VAR
  62.     aevtErr: OSErr ; theproc:procptr;
  63. BEGIN
  64.     aevtErr := AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,@HandleAEQuit, 0, false ) ;
  65.     aevtErr := AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,@HandleAEOpenApp, 0, false ) ;
  66.     END ;
  67.  
  68. {--------------------------------------------------------------------------
  69.     
  70.     Setup
  71.         Initialize our managers, Install our AppleEvent handlers, and then init the pallette code.
  72.  
  73.  --------------------------------------------------------------------------}
  74. PROCEDURE SetUp;
  75.  
  76. VAR i:integer;
  77.     numfiles:integer;
  78.     templong:longint;
  79.     io:OSErr;
  80.     p:procptr;
  81.     
  82.     Procedure DoNotRun(io:OSErr; s:str255);
  83.     begin
  84.       if io<>NoErr then begin
  85.         debugstr(s);
  86.         ExitToShell;
  87.         end;
  88.       end;
  89.       
  90.  
  91. BEGIN
  92.     
  93.     SetApplLimit(pointer(ord4(GetApplLimit)-32768)); {give an additional 32K to stack}
  94.     MaxApplZone;
  95.     InitGraf(@thePort);         {still need QuickDraw}
  96.     
  97.     doneFlag := FALSE;
  98.     
  99.     {See if we can do AppleEvents}
  100.     io:=Gestalt(gestaltAppleEventsAttr,templong);
  101.     if io=NoErr then if not odd(templong) then io:=-1;
  102.     DoNotRun(io,'Apple Events not installed');
  103.     
  104.     InstallAppleEvents;
  105.     
  106.     DoNotRun(InitLayer,'Unable to initialize our Layer stuff');
  107.     
  108.     END;    { of SetUp}
  109.  
  110. {--------------------------------------------------------------------------
  111.     
  112.     MainEventLoop
  113.         Handle our events.  As a background app, we don't do much, do we?
  114.         
  115.         We also call the pallette code's idle routine here.
  116.  
  117.  --------------------------------------------------------------------------}
  118. PROCEDURE MainEventLoop;
  119. var dummy:boolean;
  120.     io:OSErr;
  121. BEGIN
  122.     REPEAT
  123.         SetCursor(arrow);
  124.         
  125.         dummy := WaitNextEvent(everyEvent,myEvent,$7FFFFFFF,nil);
  126.         
  127.         CASE myEvent.what OF
  128.             kHighLevelEvent:
  129.                 io:=AEProcessAppleEvent( myevent ) ;                { <aevt> }
  130.             END;    { of event case }
  131.         LayerIdleProc(doneflag);
  132.         UNTIL doneFlag;
  133.     END;
  134.  
  135. BEGIN    { main program }
  136.   SetUp;
  137.   MainEventLoop;
  138.   CloseLayer;
  139.   END.
  140.